<?php
	use Common\Model\LeavelModel;
/**
	 * 使用正则验证数据
	 * @access public
	 * @param string $value  要验证的数据
	 * @param string $rule 验证规则
	 * @return boolean
	 */
	function regex($value,$rule) { 
		$validate = array(
				'email'     =>  '/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/',
				'url'       =>  '/^http(s?):\/\/(?:[A-za-z0-9-]+\.)+[A-za-z]{2,4}(:\d+)?(?:[\/\?#][\/=\?%\-&~`@[\]\':+!\.#\w]*)?$/',
				'currency'  =>  '/^\d+(\.\d+)?$/',
				'number'    =>  '/^\d+$/',
				'zip'       =>  '/^\d{6}$/',
				'integer'   =>  '/^[-\+]?\d+$/',
				'double'    =>  '/^[-\+]?\d+(\.\d+)?$/',
				'english'   =>  '/^[A-Za-z]+$/',
				// 			'name'		=>  '/[^\D]/g',
				'img'		=>	'/\.(jpg|gif|png)$/i',
				'phone'		=>  '#^13[\d]{9}$|^14[5,7]{1}\d{8}$|^15[^4]{1}\d{8}$|^17[0,6,7,8]{1}\d{8}$|^18[\d]{9}$#',
				'password'  =>  '/^[\w.]{6,20}$/',
				'bankcard'  =>  '/^(\d{16,19})$/',
				'username'  =>  '/^[\w\_]{3,20}$/u',
		);
		// 检查是否有内置的正则表达式
		if(isset($validate[strtolower($rule)]))
			$rule       =   $validate[strtolower($rule)];
		return preg_match($rule,$value)===1;
	}
	function getUserStatusName($num)
	{
	    switch ($num)
	    {
	        case 0:return '正常';break;
	        case -1:return '出局';break;
	        default:return '正常';
	    }
	}
	function getWithdrawalsStatus($num)
	{
		switch ($num)
	    {
	        case 0:return '等待系统审核';break;
	        case 1:return '审核成功请耐心等待';break;
	        case -1:return '审核未成资金退回';break;
	        default:return '等待系统审核';
	    }
	}
	function getShopBuyStatus($num)
	{
	    switch ($num)
	    {
	        case 0:return '购买成功';break;
	        case 1:return '交易完成';break;
	        default:return '正常';
	    }
	}
	function getRegTypeName($num)
	{
	    switch ($num)
	    {
	        case 1:return '100% 健康积分';break;
	        case 2:return '50% 健康积分 50% 美丽积分';break;
	        default:return '暂无';
	    }
	}
	function getSplitTypeName($num)
	{
	    switch ($num)
	    {
	        case 1:return '拆分';break;
	        case 2:return '超出静态最大拆分金额';break;
	        case 3:return '超出级别最大拆分金额';break;
	        default:return '拆分';
	    }
	}

	function getRechargeStatusName($num)
	{
	    switch ($num)
	    {
	        case 'dec':return '扣款';break;
	        case 'inc':return '增加';break;
	        default:return '正常';
	    }
	}
	function getClassByUserLeavel($status){
	    switch ($status){
	        case 1:$class='#B4A717';break;
	        case 2:$class='#0099FF';break;
	        default:$class='#B4A717';
	    }
	    return $class;
	}
	function getClassByUserStatus($status){
	    switch ($status){
	        case 0:$class='#FF3D3D';break;
	        case 1:$class='#008000';break;
	        case 2:$class='#FF69B4';break;
	        default:$class='#FF3D3D';
	    }
	    return $class;
	}
	function getLeavelName($num)
	{
	    $info=LeavelModel::newSelf()->findOneById($num);
	    return $info?$info['name']:'暂无';
	}
	function getQuyuName($num)
	{
	    switch ($num)
	    {
	        case 1:return '左区';break;
	        case 2:return '右区';break;
	        case 0:return '右区';break;
	        default:return '暂无';
	    }
	}
	function getHonorName($num)
	{
	    switch ($num)
	    {
	        case 0:return '暂无';break;
	        case 1:return '一星天使';break;
	        case 2:return '二星天使';break;
	        case 3:return '三星天使';break;
	        case 4:return '四星天使';break;
	        case 5:return '五星天使';break;
	        case 6:return '六星天使';break;
	        case 7:return '七星天使';break;
	        default:return '暂无';
	    }
	}
	function getTradeSellStatus($num)
	{
	    switch ($num)
	    {
	        case 0:return '匹配中';break;
	        case -1:return '撤单';break;
	        case 1:return '交易完成';break;
	        case -2:return '系统撤单';break;
	        default:return '暂无';
	    }
	}
	function getTradeBuyStatus($num)
	{
	    switch ($num)
	    {
	        case 0:return '匹配中';break;
	        case -1:return '撤单';break;
	        case 1:return '交易完成';break;
	        case -2:return '系统撤单';break;
	        default:return '暂无';
	    }
	}
	function getSellStatus($num)
	{
	    switch ($num)
	    {
	        case 0:return '等待用户购买';break;
	        case 1:return '等待用户付款';break;
	        case 2:return '等待确认收款';break;
	        case 3:return '交易成功';break;
	        case -1:return '撤单成功';break;
	        default:return '暂无';
	    }
	}
	function getUserBankName($num)
	{
	    switch ($num)
	    {
	        case 0:return '暂无';break;
	        case 1:return '中国农业银行';break;
	        case 2:return '中国工商银行';break;
	        case 3:return '中国建设银行';break;
	        case 4:return '中国银行';break;
	        case 5:return '招商银行';break;
	        default:return '暂无';
	    }
	}
	function getOrderStatus($num)
	{
	    switch ($num)
	    {
	        case 0:return '发货中';break;
	        case 1:return '已发货';break;
	        default:return '发货中';
	    }
	}
	function getPayStatus($num)
	{
	    switch ($num)
	    {
	        case 0:return '等待审核';break;
	        case 1:return '审核通过';break;
	        case -1:return '审核未通过';break;
	        default:return '等待审核';
	    }
	}
	function getLockStatus($num)
	{
	    switch ($num)
	    {
	        case 0:return '正常';break;
	        case 1:return '冻结';break;
	        default:return '正常';
	    }
	}
	function getMessageTypeName($num)
	{
	    switch ($num)
	    {
	        case 1:return '帮助';break;
	        case 2:return '奖金';break;
	        case 3:return '提现';break;
	        case 4:return '充值';break;
	        case 5:return '其他';break;
	        case 6:return '咨询';break;
	        case 13:return '管理员回复';break;
	        default:return '其他';
	    }
	}
	function getDateFormat($num)
	{
	    if ($num) {
	       return date('Y-m-d H:i:s',$num);
	    }
	    return '###';
	}
	function getNumOfPublicNetwork($num)
	{
        $count = 0; 
        while($num>=2){ 
            $num=$num/2; 
            $count++; 
        } 
        $count++; 
        return $count; 
	}
	function getDateFormatSpecial($num)
	{
	    return date('Y-m-d',$num);
	}
    function phoneCode($phone,$code_name,$reg=false){
        $smsapi = "https://api.mysubmail.com/message/send.json";
        $time=session('time'.$code_name.$phone);
        if (time()-$time<180&&!empty($time)){
        	return false;
        }
        if($reg){
	        $content=urlencode("【天顺商贸】[tianshun.club] 您已注册成功,欢迎加入天顺商贸！");
        }else{
	        $code=rand(1000, 9999);
	        session('code'.$code_name.$phone,$code); 
	        session('time'.$code_name.$phone,time(),1800);
	        $content=urlencode("【天顺商贸】[tianshun.club]欢迎加入天顺！您的验证码是".$code."，您的手机已成功绑定，日后资金变动短信验证码会发送至该手机，请勿将验证码告诉他人！");
        }
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, 'https://api.mysubmail.com/message/send.json');
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); 
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); 
        curl_setopt($curl, CURLOPT_POST, 1);
        $sendurl ='appid=18830&to='.$phone.'&content='.$content.'&signature=c18067508948f2640807a387f1ca9b6a';
        curl_setopt($curl, CURLOPT_AUTOREFERER, 1); 
        curl_setopt($curl, CURLOPT_POST, 1); 
        curl_setopt($curl, CURLOPT_POSTFIELDS, $sendurl); 
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $data = curl_exec($curl);
        curl_close($curl);
        $res=json_decode($data);
        return $res;
    }
    function checkPhoneCode($phoneCode,$code_name,$phone){
    	$code=session('code'.$code_name.$phone); 
    	if($phoneCode!=$code){
    		return false;
    	}else{
    		session('code'.$code_name.$phone,null);
    		return true;
    	}
    }
